<form id="add-form" class="form-horizontal" method="POST" action="{:url('gsave')}">
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">模块名称:</label>
        <div class="col-xs-12 col-sm-8">
            <select class="form-control" name="model_id" id="model_id">
                {volist name="models" id="vo"}
                  <option value="{$vo.id}" {if condition="(!empty($data)) AND $vo['id'] eq $data['model_id']"}selected{/if}>{$vo.name}</option>
                {/volist} 
            </select>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">功能名称:</label>
        <div class="col-xs-12 col-sm-8">
            <select class="form-control" name="gid" id="gid">
                 {volist name="gongnen" id="vo"}
                  <option value="{$vo.id}" {if condition="(!empty($data)) AND $vo['id'] eq $data['gid']"}selected{/if}>{$vo.name}</option>
                {/volist} 
            </select>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">功能描述:</label>
        <div class="col-xs-12 col-sm-8" id="gongnen_des">
            {volist name="child" id="vo"}
             <label style="font-weight: normal;margin-right: 15px;cursor: pointer;">
                 {$vo.cname} <input style="position: relative;top: 2px;" name="child_id[]" {if condition="(!empty($data)) AND in_array($vo['id'],$data['tech_id'])"}checked{/if} value="{$vo.id}" type="checkbox">
             </label>
            {/volist}
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <input type="hidden" name="page_id" value="{$page_id}" class="form-control"/>
            <input type="hidden" name="id" value="{$data['id']|default=''}" class="form-control"/>
            <button type="submit" class="btn btn-success btn-embossed">{:__('OK')}</button>
        </div>
    </div>
</form>

<script>
    var page_id="{$page_id}";
    $(function(){
        $("#gid").change(function(){
            var gid = $(this).val();
        
            ajaxGetChild(gid);
            return false;
        });

        $("#model_id").change(function(){
            var model_id = $(this).val();
            $.ajax({
                type:'POST',
                data:{
                    model_id:model_id,
                    page_id:page_id,
                },
                url:"{:url('ajaxGetGongNen')}",
                success:function(data){
                    if(data.code==1){
                        $("#gid").html(data.msg.html);
                        $("#gongnen_des").html(data.msg.child_html);
                    }else{
                        alert("服务器错误");
                    }
                }
            });
            return false;
        });

    })

    function ajaxGetChild(gid){
         var model_id = $("#model_id").val();
         $.ajax({
                type:'POST',
                data:{
                    page_id:page_id,
                    model_id:model_id,
                    gid:gid,
                },
                url:"{:url('ajaxGetChild')}",
                success:function(data){
                    if(data.code==1){
                         $("#gongnen_des").html(data.msg);
                    }else{
                        alert("服务器错误");
                    }
                }
            });

    }
</script>